home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8377 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: news.xnet.com!kato
  2. From: kato@flood.xnet.com (Ian Curtis)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Leap Years
  5. Date: 3 Mar 1996 20:43:59 GMT
  6. Organization: XNet - A Full Service Internet Provider - (708) 983-6064
  7. Message-ID: <4hd0af$r6k@flood.xnet.com>
  8. References: <8BA8405.02C70020E1.uuout@sourcebbs.com> <4h6ara$mu@netnews1.apci.com>
  9. NNTP-Posting-Host: cyclone.xnet.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Martin Ward (wardmw@apci.com) wrote:
  13. : david.mohorn@sourcebbs.com (DAVID MOHORN) typed:
  14.  
  15. : >How do you feature out leap years?  If its evenly divisible by 400 and
  16. : >4?
  17.  
  18. The year does not have to be evenly divisible by 400 to qualify as a leap 
  19. year. This year is a leap year - 1996 is not divisible by 400 (evenly at 
  20. least) Besides that, anything divisible by 400 is divisible by 4, by 
  21. definition. Martin's code will return a TRUE value for any number 
  22. divisible by 4 (except 4000 and 100). The only qualifications I know if 
  23. are these: must be between 1900 and 2100 (I may be wrong about the years)  
  24. and be divisble by four (hopefully no debate there ;) ). In this case, the 
  25. appropriate code would be:
  26.  
  27. int IsLeap(int year)
  28. {
  29.     if((year>1900) && (year<2100) && (year%4==0))
  30.         return 1;
  31.     else return 0;
  32. }
  33.  
  34.  
  35. : The following code will do it:
  36.  
  37. : /* Return TRUE if iYear is a leap year, otherwise return FALSE */
  38.  
  39. : int IsLeapYear(int iYear)
  40. : {
  41. :     /* Check for a 4000th year */ 
  42. :     if ( (iYear % 4000) == 0)
  43. :         return FALSE;
  44.  
  45. :     /* Check for 400th year */
  46. :     if ( (iYear % 400) == 0)
  47. :         return TRUE;
  48.  
  49. :     /* Check for century */
  50. :     if ( (iYear % 100) == 0 )
  51. :         return FALSE;
  52.  
  53. :     /* C
  54. :     if ( (iYear % 4) == 0 )
  55. :         return TRUE;
  56.  
  57. :     return FALSE;
  58. : }
  59.  
  60. : HTH.
  61.  
  62. : |\/|
  63.  
  64.  
  65. --
  66.          Ian Curtis (kato@monsoon.xnet.com - telnet xnet.com 8888) 
  67.           My opinions are most likely NOT those of the US Navy...
  68.